Repository navigation
fix(#946): builtinTools "none" guard passes only mcp__ tools; boot test catches a dropped threadRoles lookup - #1032
Conversation
…st catches a dropped threadRoles lookup The guard no longer allows a call because hook_event_name is not "PreToolUse": whatever the event name says (missing, empty, another event), only an mcp__ tool passes. ThreadRoleTargets.layer makes a "ThreadRoleTargets.make" span, and the real-server boot test lists it with the fork's other layer spans, so a server that loses it from layerRuntimeServices fails that test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
lens: code · reviewer: lens agent (Claude Code) · read at: 6adb49d 🤖 Generated with Claude Code |
|
lens: state · reviewer: lens agent · read at: 6adb49d 🤖 Generated with Claude Code |
…ts event name The server-list guard returned allow when hook_event_name was not "PreToolUse", so with servers ["gh"] and a missing or other event name a call like mcp__x__Bash (server x, not listed) passed. The guard is registered only under PreToolUse, so the check is dropped, as it was for the builtinTools "none" guard. The event-name test loop is shared by both guards: for a missing, undefined, empty, "PostToolUse", "pretooluse" or numeric event name, each call made twice, a left-out server's tool is refused and a listed server's tool passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both follow-ups from the round-2 reviews of #927 and #928.
Item 1: builtinTools "none" guard (#927)
apps/server/src/fork/claudeMcpProfile.ts: the guard no longer returns allow whenhook_event_nameis not"PreToolUse". It does not read the event name at all now. A call passes only whentool_nameis a string that starts withmcp__. Anything else is refused. The existing fail-closed paths are unchanged: a tool name that is not a string, or an error while checking, is refused.Test (
claudeMcpProfile.adapter.test.ts, new case): the event name is missing,undefined,"","PostToolUse","pretooluse"or a number. For each,Bashis refused andmcp__t3-code__t3_thread_listpasses, and each call is made twice. Before the fix the test was red on the first case (Bash, event missing, try 1: expected undefined to equal 'deny'). After the fix all 13 tests in the file pass.Item 2: end-to-end check for
ThreadRoleTargets.layer(#928)The issue left this for the later Settings PR. It was small, so it is done here.
apps/server/src/fork/threadRoleTargetsLayer.ts: building the layer now records aThreadRoleTargets.makespan.apps/server/src/holdWork.boot.test.ts:ThreadRoleTargets.makeis added toFORK_LAYER_SPANS. These are the spans the test expects from a realt3 serveboot (server.ts with everything wired).Red, green and mutation runs:
expected [ 'ThreadRoleTargets.make' ] to deeply equal []).ThreadRoleTargets.layer,removed fromlayerRuntimeServicesinforkLayers.ts: red with the same message. The line was put back afterwards.What this covers: the layer is built in the real server. Where it sits in server.ts is not new. It is in the same
Layer.mergeAllasSlotGate, insidelayerRuntimeCoreDependenciesBase, which the #928 review traced to the settings save.State question
Can a hook call that is repeated, that has an old or empty event name, or that comes before the profile is read ever let a built-in tool through when the profile says none? No.
tool_name. A missing, empty, older or unknownhook_event_namecannot lead to an allow.builtinTools: "none"is built. That same plan also starts Claude withtools: []and every built-in tool indisallowedTools. A process opened before the profile was read is the old process, which still has its tools. A thread that changes tononegets a new process for its next turn, because the plan key holdsbuiltin none(as fork: MCP profile builtinTools "none" (assistant PR 1) #927 described), so no turn undernoneruns without the guard.Round 1
Both lenses said safe to merge and named the same minor.
claudeMcpProfile.ts:278: the server-list guard (claudeMcpProfileGuard) still returned allow whenhook_event_namewas not"PreToolUse". Withservers: ["gh"]and a missing orPostToolUseevent name,mcp__x__Bash(server x, not listed) passed.PreToolUse(claudeMcpServersPlan;claudeMcpProfilePlanandwithAgentModelPolicykeep it there), so the input is read as aPreToolUseHookInputwhatever its event name.servers: ["gh"]profile: for a missing,undefined, empty,"PostToolUse","pretooluse"or numeric event name, each call made twice,mcp__x__Bashis refused andmcp__gh__list_issuespasses. Red on 6adb49d (mcp__x__Bash, event missing, try 1: expected a deny), green after the fix: 14/14.The state lens asked to leave this out: #946 names only the built-in guard, the server guard's main barriers (strict MCP config or the allowlist, and the post-start server check) are unchanged, and a second guard's answer changing needs its own tests and review. It was fixed here anyway: it is the same one-line change as item 1, it has its own test in the same pattern, and it makes this backup guard refuse by default instead of allowing on an event name it should not trust.
Not changed: a hook input with no string
tool_name(and nomcp_server) still makes this guard throw, which Claude Code treats as a non-blocking error. Before this round such an input with an odd event name was allowed outright, so this is no looser than before.Checks
claudeMcpProfile.adapter.test.ts: 14/14 (13/13 before round 1)holdWork.boot.test.ts: 2/2threadRoleTargetsLayer.test.ts: 4/4vp run check:changed: format, lint, knip, graphql, typecheck and tests (5 files, 79 tests after round 1) all pass.fork-seam-check.cjs origin/main HEAD: exit 0. No upstream file is changed, so there are no new seam lines.General vs project
FORK_LAYER_SPANSin the boot test is this fork's way of showing that the real server wires a fork layer.ThreadRoleTargetsis now one of those layers.Fixes #946
🤖 Generated with Claude Code